﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using SvnAPI.Base.Enumerator;
using SvnAPI.Command.Base;
using SvnAPI.Command.Interface;
using System;

namespace SvnAPITest.CommandTest
{
    /// <summary>
    /// Class to execute tests on the svn look command.
    /// </summary>
    [TestClass]
    public class SvnLookCommandTest
    {
        #region Methods

        #region TestError

        /// <summary>
        /// Execute the command get author without use a transaction.
        /// </summary>
        [TestMethod]
        public void GetAuthorNoTransaction()
        {
            try
            {
                using (var cmd = Command.LookCommand("48b", @"C:\Repositories\Sabesp"))
                {
                    using (IResult result = cmd.Author(ExecutionType.transaction))
                    {
                        Assert.AreEqual(result.Error, "svnlook: E160007: No such transaction '48b'");
                    }
                }
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            } 
        }

        /// <summary>
        /// Execute the command get author without use a revision.
        /// </summary>
        [TestMethod]
        public void GetAuthorNoRevision()
        {
            try
            {
                using (var cmd = Command.LookCommand("48b", @"C:\Repositories\Sabesp"))
                {
                    using (IResult result = cmd.Author(ExecutionType.revision))
                    {
                        Assert.AreEqual(result.Error, "svn: E205000: Invalid revision number supplied");
                    }
                }
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }

        /// <summary>
        /// Execute the command get cat without use a transaction.
        /// </summary>
        [TestMethod]
        public void GetCatNoTransaction()
        {
            try
            {
                using (var cmd = Command.LookCommand("48b", @"C:\Repositories\Sabesp", @"D:\Projetos\Sabesp\Sabesp41\products\signos\product.def"))
                {
                    using (IResult result = cmd.Cat(ExecutionType.transaction))
                    {
                        Assert.AreEqual(result.Error, "svnlook: E160007: No such transaction '48b'");
                    }
                }
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }

        /// <summary>
        /// Execute the command get cat without use a revision.
        /// </summary>
        [TestMethod]
        public void GetCatNoRevision()
        {
            try
            {
                using (var cmd = Command.LookCommand("48b", @"C:\Repositories\Sabesp", @"D:\Projetos\Sabesp\Sabesp41\products\signos\product.def"))
                {
                    using (IResult result = cmd.Cat(ExecutionType.revision))
                    {
                        Assert.AreEqual(result.Error, "svn: E205000: Invalid revision number supplied");
                    }
                }
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }

        /// <summary>
        /// Execute the command get changed without use a transaction.
        /// </summary>
        [TestMethod]
        public void GetChangedNoTransaction()
        {
            try
            {
                using (var cmd = Command.LookCommand("48b", @"C:\Repositories\Sabesp"))
                {
                    using (IResult result = cmd.Changed(ExecutionType.transaction))
                    {
                        Assert.AreEqual(result.Error, "svnlook: E160007: No such transaction '48b'");
                    }
                }
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }

        /// <summary>
        /// Execute the command get changed without use a revision.
        /// </summary>
        [TestMethod]
        public void GetChangedNoRevision()
        {
            try
            {
                using (var cmd = Command.LookCommand("48b", @"C:\Repositories\Sabesp"))
                {
                    using (IResult result = cmd.Changed(ExecutionType.revision))
                    {
                        Assert.AreEqual(result.Error, "svn: E205000: Invalid revision number supplied");
                    }
                }
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }

        /// <summary>
        /// Execute the command get changed without use a transaction.
        /// </summary>
        [TestMethod]
        public void GetDateNoTransaction()
        {
            try
            {
                using (var cmd = Command.LookCommand("48b", @"C:\Repositories\Sabesp"))
                {
                    using (IResult result = cmd.Date(ExecutionType.transaction))
                    {
                        Assert.AreEqual(result.Error, "svnlook: E160007: No such transaction '48b'");
                    }
                }
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }

        /// <summary>
        /// Execute the command get changed without use a revision.
        /// </summary>
        [TestMethod]
        public void GetDateNoRevision()
        {
            try
            {
                using (var cmd = Command.LookCommand("48b", @"C:\Repositories\Sabesp"))
                {
                    using (IResult result = cmd.Date(ExecutionType.revision))
                    {
                        Assert.AreEqual(result.Error, "svn: E205000: Invalid revision number supplied");
                    }
                }
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }

        /// <summary>
        /// Execute the command get changed without use a transaction.
        /// </summary>
        [TestMethod]
        public void GetDiffNoTransaction()
        {
            try
            {
                using (var cmd = Command.LookCommand("48b", @"C:\Repositories\Sabesp"))
                {
                    using (IResult result = cmd.Diff(ExecutionType.transaction))
                    {
                        Assert.AreEqual(result.Error, "svnlook: E160007: No such transaction '48b'");
                    }
                }
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }

        /// <summary>
        /// Execute the command get changed without use a revision.
        /// </summary>
        [TestMethod]
        public void GetDiffNoRevision()
        {
            try
            {
                using (var cmd = Command.LookCommand("48b", @"C:\Repositories\Sabesp"))
                {
                    using (IResult result = cmd.Diff(ExecutionType.revision))
                    {
                        Assert.AreEqual(result.Error, "svn: E205000: Invalid revision number supplied");
                    }
                }
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }

        /// <summary>
        /// Execute the command get changed without use a transaction.
        /// </summary>
        [TestMethod]
        public void GetDirsChangedNoTransaction()
        {
            try
            {
                using (var cmd = Command.LookCommand("48b", @"C:\Repositories\Sabesp"))
                {
                    using (IResult result = cmd.DirsChanged(ExecutionType.transaction))
                    {
                        Assert.AreEqual(result.Error, "svnlook: E160007: No such transaction '48b'");
                    }
                }
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }

        /// <summary>
        /// Execute the command get changed without use a revision.
        /// </summary>
        [TestMethod]
        public void GetDirsChangedNoRevision()
        {
            try
            {
                using (var cmd = Command.LookCommand("48b", @"C:\Repositories\Sabesp"))
                {
                    using (IResult result = cmd.DirsChanged(ExecutionType.revision))
                    {
                        Assert.AreEqual(result.Error, "svn: E205000: Invalid revision number supplied");
                    }
                }
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }

        /// <summary>
        /// Execute the command get changed without use a transaction.
        /// </summary>
        [TestMethod]
        public void GetFileSizeNoTransaction()
        {
            try
            {
                using (var cmd = Command.LookCommand("48b", @"C:\Repositories\Sabesp", @"D:\Projetos\Sabesp\Sabesp41\products\signos\product.def"))
                {
                    using (IResult result = cmd.FileSize(ExecutionType.transaction))
                    {
                        Assert.AreEqual(result.Error, "svnlook: E160007: No such transaction '48b'");
                    }
                }
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }

        /// <summary>
        /// Execute the command get changed without use a revision.
        /// </summary>
        [TestMethod]
        public void GetFileSizeNoRevision()
        {
            try
            {
                using (var cmd = Command.LookCommand("48b", @"C:\Repositories\Sabesp", @"D:\Projetos\Sabesp\Sabesp41\products\signos\product.def"))
                {
                    using (IResult result = cmd.FileSize(ExecutionType.revision))
                    {
                        Assert.AreEqual(result.Error, "svn: E205000: Invalid revision number supplied");
                    }
                }
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }

        /// <summary>
        /// Execute the command get changed without use a revision.
        /// </summary>
        [TestMethod]
        public void GetHistoryNoRevision()
        {
            try
            {
                using (var cmd = Command.LookCommand("48b", @"C:\Repositories\Sabesp", @"D:\Projetos\Sabesp\Sabesp41\products\signos\product.def"))
                {
                    using (IResult result = cmd.History(ExecutionType.revision))
                    {
                        Assert.AreEqual(result.Error, "svn: E205000: Invalid revision number supplied");
                    }
                }
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }

        /// <summary>
        /// Execute the command get changed without use a transaction.
        /// </summary>
        [TestMethod]
        public void GetInfoNoTransaction()
        {
            try
            {
                using (var cmd = Command.LookCommand("48b", @"C:\Repositories\Sabesp"))
                {
                    using (IResult result = cmd.Info(ExecutionType.transaction))
                    {
                        Assert.AreEqual(result.Error, "svnlook: E160007: No such transaction '48b'");
                    }
                }
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }

        /// <summary>
        /// Execute the command get changed without use a revision.
        /// </summary>
        [TestMethod]
        public void GetInfoNoRevision()
        {
            try
            {
                using (var cmd = Command.LookCommand("48b", @"C:\Repositories\Sabesp"))
                {
                    using (IResult result = cmd.Info(ExecutionType.revision))
                    {
                        Assert.AreEqual(result.Error, "svn: E205000: Invalid revision number supplied");
                    }
                }
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }

        /// <summary>
        /// Execute the command get changed without use a revision.
        /// </summary>
        [TestMethod]
        public void GetLock()
        {
            try
            {
                using (var cmd = Command.LookCommand("48b", @"C:\Repositories\Sabesp", @"D:\Projetos\Sabesp\Sabesp41\products\signos\product.def"))
                {
                    using (IResult result = cmd.Lock())
                    {
                        Assert.AreEqual(result.Error, "");
                    }
                }
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }

        /// <summary>
        /// Execute the command get changed without use a transaction.
        /// </summary>
        [TestMethod]
        public void GetLogTransaction()
        {
            try
            {
                using (var cmd = Command.LookCommand("48b", @"C:\Repositories\Sabesp"))
                {
                    using (IResult result = cmd.Log(ExecutionType.transaction))
                    {
                        Assert.AreEqual(result.Error, "svnlook: E160007: No such transaction '48b'");
                    }
                }
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }

        /// <summary>
        /// Execute the command get changed without use a revision.
        /// </summary>
        [TestMethod]
        public void GetLogNoRevision()
        {
            try
            {
                using (var cmd = Command.LookCommand("48b", @"C:\Repositories\Sabesp"))
                {
                    using (IResult result = cmd.Log(ExecutionType.revision))
                    {
                        Assert.AreEqual(result.Error, "svn: E205000: Invalid revision number supplied");
                    }
                }
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }

        /// <summary>
        /// Execute the command get changed without use a transaction.
        /// </summary>
        [TestMethod]
        public void GetTreeNoTransaction()
        {
            try
            {
                using (var cmd = Command.LookCommand("48b", @"C:\Repositories\Sabesp", @"D:\Projetos\Sabesp\Sabesp41\products\signos\product.def"))
                {
                    using (IResult result = cmd.Tree(ExecutionType.transaction))
                    {
                        Assert.AreEqual(result.Error, "svnlook: E160007: No such transaction '48b'");
                    }
                }
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }

        /// <summary>
        /// Execute the command get changed without use a revision.
        /// </summary>
        [TestMethod]
        public void GetTreeNoRevision()
        {
            try
            {
                using (var cmd = Command.LookCommand("48b", @"C:\Repositories\Sabesp", @"D:\Projetos\Sabesp\Sabesp41\products\signos\product.def"))
                {
                    using (IResult result = cmd.Tree(ExecutionType.revision))
                    {
                        Assert.AreEqual(result.Error, "svn: E205000: Invalid revision number supplied");
                    }
                }
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }

        /// <summary>
        /// Execute the command get changed without use a revision.
        /// </summary>
        [TestMethod]
        public void GetUUId()
        {
            try
            {
                using (var cmd = Command.LookCommand("48b", @"C:\Repositories\Sabesp"))
                {
                    using (IResult result = cmd.UUId())
                    {
                        Assert.AreEqual(result.Output, "5d796a80-9cb5-2a4a-862f-d9fe5f56dad2");
                    }
                }
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }

        /// <summary>
        /// Execute the command get changed without use a revision.
        /// </summary>
        [TestMethod]
        public void GetYoungest()
        {
            try
            {
                using (var cmd = Command.LookCommand("48b", @"C:\Repositories\Sabesp"))
                {
                    using (IResult result = cmd.Youngest())
                    {
                        Assert.AreEqual(result.Output, "2");
                    }
                }                
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }

        #endregion

        #region TestSuccessed

        /// <summary>
        /// Execute the command get author using a revision.
        /// </summary>
        [TestMethod]
        public void GetAuthorRevision()
        {
            try
            {
                using (var cmd = Command.LookCommand("2", @"C:\Repositories\Sabesp"))
                {
                    using (IResult result = cmd.Author(ExecutionType.revision))
                    {
                        Assert.AreEqual(result.Output, "dleonardo");
                    }
                }                
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }

        #endregion

        #endregion
    }
}
